
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.net.*;
import java.io.*;
/*
 * Gui1.java
 *
 * Created on October 31, 2008, 1:00 PM
 */
import java.util.HashMap;



/**
 *
 * @author  kushwaham1
 */
public class Gui1 extends javax.swing.JFrame {
    private Component JFrame;
    Gui0 myGui0;
    Gui2 myGui2;
    private HashMap<String,Gui2> HashChatInstance=new HashMap();
    private HashMap<String,String> HashOnline =new HashMap();
    int guiCount;
    /** Creates new form Gui1 */
    public Gui1(Gui0 myGui0, String[] temp) {
        initComponents();
        this.myGui0=myGui0;
        guiCount=0;
        for (int i=1; i<temp.length; i++){
            String [] temp1=null;
            temp1=temp[i].split(":");
            lmNames.addElement(temp1[0]);
            if (temp1[1].equalsIgnoreCase("O")){
                HashOnline.put(temp1[0], temp1[1]);
            }
            else{
                HashOnline.put(temp1[0], "I");
            }
            //jList1.setSelectedIndex(lmNames.size() - 1);
        }
        //System.out.println(myGui0.getUserId());
        setTitle(myGui0.getUserId()+"'s"+"Messenger");
        //setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        Driver myDriver=new Driver(myGui0,this);
        Thread theThread =new Thread(myDriver);
        theThread.start();
        
    }

public void passMessage(String BuddyId, String msg){
    if (guiCount==0){
        myGui2= new Gui2(BuddyId, myGui0, this);
        HashChatInstance.put(BuddyId, myGui2);
        HashChatInstance.get(BuddyId).setVisible(true);
        guiCount=1;
        HashChatInstance.get(BuddyId).updateMessage(BuddyId,msg);
    }
    else{
        HashChatInstance.get(BuddyId).setVisible(true);
        HashChatInstance.get(BuddyId).updateMessage(BuddyId,msg);
    }
    
    
}

public void updateOnlineHash(String BuddyId){
    if (HashOnline.containsKey(BuddyId)==false){
        HashOnline.put(BuddyId, "O");
    }
}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jLabel20 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lmNames = new DefaultListModel();
        jList1 = new javax.swing.JList(lmNames);
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem11 = new javax.swing.JMenuItem();
        jMenuItem12 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu7 = new javax.swing.JMenu();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem14 = new javax.swing.JMenuItem();
        jMenuItem13 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem16 = new javax.swing.JMenuItem();
        jMenuItem15 = new javax.swing.JMenuItem();
        jMenuItem17 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem23 = new javax.swing.JMenuItem();
        jMenuItem18 = new javax.swing.JMenuItem();
        jMenuItem19 = new javax.swing.JMenuItem();
        jMenuItem24 = new javax.swing.JMenuItem();
        jMenuItem20 = new javax.swing.JMenuItem();
        jMenuItem22 = new javax.swing.JMenuItem();
        jMenuItem21 = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem26 = new javax.swing.JMenuItem();
        jMenu6 = new javax.swing.JMenu();
        jMenuItem27 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Display Picture");
        jLabel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jLabel2.setText("Display Name");

        jLabel3.setText("Status");

        jLabel4.setText("Display Message");

        jButton1.setText("Edit Personal Settings");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                personalSetting(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jButton1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton2.setText("Add Buddy");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddBuddy(evt);
            }
        });

        jButton3.setText("Call");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Call(evt);
            }
        });

        jButton4.setText("Conference");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Conference(evt);
            }
        });

        jButton5.setText("Webcam");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Webcam(evt);
            }
        });

        jButton6.setText("Intiate Chat");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                IntiateChat(evt);
            }
        });

        jButton7.setText(" Remove Buddy");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteBuddy(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5)
                    .addComponent(jButton4)
                    .addComponent(jButton3)
                    .addComponent(jButton6)
                    .addComponent(jButton2)))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jLabel20.setText("Advertisement");
        jLabel20.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));

        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                DoubleClickListener(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jMenu1.setText("Messenger");

        jMenuItem2.setText("Sign Out");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SignOut(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem3.setText("Status");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Status(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem4.setText("Message History");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShowConversationLog(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem5.setText("Exit");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Exit(evt);
            }
        });
        jMenu1.add(jMenuItem5);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Contacts");

        jMenuItem6.setText("Add a Contact");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddBuddy(evt);
            }
        });
        jMenu2.add(jMenuItem6);

        jMenuItem1.setText("Edit a Contact");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditBuddyInfo(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem10.setText("Delete a Contact");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteBuddy(evt);
            }
        });
        jMenu2.add(jMenuItem10);

        jMenuItem11.setText("Create a Group");
        jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CreateGroup(evt);
            }
        });
        jMenu2.add(jMenuItem11);

        jMenuItem12.setText("Edit a group");
        jMenuItem12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditGroup(evt);
            }
        });
        jMenu2.add(jMenuItem12);

        jMenuItem9.setText("Delete a group");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DeleteGroup(evt);
            }
        });
        jMenu2.add(jMenuItem9);

        jMenu7.setText("Filter By");

        jMenuItem8.setText("Email Address");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FilterEmail(evt);
            }
        });
        jMenu7.add(jMenuItem8);

        jMenuItem14.setText("Names");
        jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FilterNames(evt);
            }
        });
        jMenu7.add(jMenuItem14);

        jMenuItem13.setText("Groups");
        jMenuItem13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FilterGroup(evt);
            }
        });
        jMenu7.add(jMenuItem13);

        jMenu2.add(jMenu7);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("Buddy");

        jMenuItem16.setText("Open Contact Card for buddy");
        jMenuItem16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ContactCard(evt);
            }
        });
        jMenu3.add(jMenuItem16);

        jMenuItem15.setText("Ignore/Block buddy");
        jMenuItem15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Ignore(evt);
            }
        });
        jMenu3.add(jMenuItem15);

        jMenuItem17.setText("Show Conversation Logs");
        jMenuItem17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ShowConversationLog(evt);
            }
        });
        jMenu3.add(jMenuItem17);

        jMenuBar1.add(jMenu3);

        jMenu4.setText("Actions");

        jMenuItem23.setText("Open IM");
        jMenuItem23.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OpenIM(evt);
            }
        });
        jMenu4.add(jMenuItem23);

        jMenuItem18.setText("Call Computer");
        jMenuItem18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CallComputer(evt);
            }
        });
        jMenu4.add(jMenuItem18);

        jMenuItem19.setText("Call Settings");
        jMenuItem19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CallSetting(evt);
            }
        });
        jMenu4.add(jMenuItem19);

        jMenuItem24.setText("Invite to View Webcam");
        jMenuItem24.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InviteWebcam(evt);
            }
        });
        jMenu4.add(jMenuItem24);

        jMenuItem20.setText("Webcam Settings");
        jMenuItem20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WebcamSetting(evt);
            }
        });
        jMenu4.add(jMenuItem20);

        jMenuItem22.setText("Invite to Conference");
        jMenuItem22.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InviteConference(evt);
            }
        });
        jMenu4.add(jMenuItem22);

        jMenuItem21.setText("Join a conference");
        jMenuItem21.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JoinConference(evt);
            }
        });
        jMenu4.add(jMenuItem21);

        jMenuBar1.add(jMenu4);

        jMenu5.setText("Tools");

        jMenuItem26.setText("All Preference");
        jMenuItem26.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AllPreference(evt);
            }
        });
        jMenu5.add(jMenuItem26);

        jMenuBar1.add(jMenu5);

        jMenu6.setText("Help");

        jMenuItem27.setText("Call Manish for further Assistance");
        jMenuItem27.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CallManish(evt);
            }
        });
        jMenu6.add(jMenuItem27);

        jMenuBar1.add(jMenu6);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(30, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AddBuddy(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddBuddy
        // TODO add your handling code here:
        
        Gui9 dialog = new Gui9(this, true, myGui0);
        dialog.setVisible(true);
    }//GEN-LAST:event_AddBuddy
    public void removeupdatelist(){
        int index = jList1.getSelectedIndex();
        lmNames.remove(index);
    }
    public void addupdateList(String BuddyId){
        lmNames.addElement(BuddyId);
        jList1.setSelectedIndex(lmNames.size() - 1);
        
        System.out.println("Starting server connection to check whether buddy is online");
        String serverName;
        String response;
        BufferedReader in;
        PrintWriter out;
        Socket clientSocket = null;
        try {
            clientSocket = new Socket(Gui0.serverName, 2000);
            in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            out = new PrintWriter(clientSocket.getOutputStream(), true);
            out.println("CheckBuddyOnline"+","+BuddyId);
            response = in.readLine();
            //JOptionPane.showMessageDialog(new javax.swing.JFrame(), response);
            if (response.equalsIgnoreCase("O")) {
                HashOnline.put(BuddyId, "O");
            } 
            else {
                HashOnline.put(BuddyId, "I");
  
            }
        } catch (IOException e) {
            System.out.println("Error in communication! in Gui1 add UpdateList");
        }
        
    }
    private void Call(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Call
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_Call

    private void Conference(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Conference
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_Conference

    private void personalSetting(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_personalSetting
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_personalSetting

    private void Webcam(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Webcam
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_Webcam

    private void EditBuddyInfo(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditBuddyInfo
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(new javax.swing.JFrame(), "Will Open Gui9 with Buddy information");
}//GEN-LAST:event_EditBuddyInfo

    private void SignOut(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SignOut
        // TODO add your handling code here:
        Gui6 dialog = new Gui6(this, true, myGui0);
        dialog.setVisible(true);
        
        
        
        
    }//GEN-LAST:event_SignOut

    private void DeleteBuddy(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteBuddy
        // TODO add your handling code here:
        if (jList1.getSelectedValue()==null){
            JOptionPane.showMessageDialog(new javax.swing.JFrame(), "Please Select a buddy from the list");
        }
        else{
            Object BuddyId=jList1.getSelectedValue();
            //Gui0 dialogGui0 = new Gui0();
            String UserId =myGui0.getUserId();
            //System.out.println("So the Buddy Id which is to be removed is:"+BuddyId);
            String removeBuddyString= "Remove Buddy"+","+UserId+","+BuddyId;

            String serverName;
            String response;
            BufferedReader in;
            PrintWriter out;
            Socket clientSocket = null;
            try{
                //System.out.println("connecting to host");
                //serverName = "localhost";
                clientSocket = new Socket(Gui0.serverName, 2000);
                in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                out = new PrintWriter(clientSocket.getOutputStream(), true);
                out.println(removeBuddyString);
                System.out.println("Waiting for response for remove Buddy");
                response= in.readLine();
                //System.out.println("Response from server:"+ response);
                JOptionPane.showMessageDialog(new javax.swing.JFrame(), response);
                if (response.equalsIgnoreCase("Buddy Removed")){
                    //dispose();
                    this.removeupdatelist();
                    HashOnline.remove(BuddyId);
                    HashChatInstance.remove(BuddyId);
                }
                else{
                    //don't need else I guess
                    JOptionPane.showMessageDialog(new javax.swing.JFrame(), "Please select correct Buddy ID");
                }
            }
            catch (IOException e){
                System.out.println("Error in communication! in Gui1 Delete");
            }
        }
        //new Gui10().setVisible(true);
        
        
    }//GEN-LAST:event_DeleteBuddy

    private void CreateGroup(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreateGroup
        // TODO add your handling code here:
        Gui4 dialog = new Gui4(new javax.swing.JFrame(), true);
        dialog.setVisible(true);
    }//GEN-LAST:event_CreateGroup

    private void EditGroup(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditGroup
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_EditGroup

    private void DeleteGroup(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteGroup
        // TODO add your handling code here:
        new Gui11().setVisible(true);
    }//GEN-LAST:event_DeleteGroup

    private void FilterEmail(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FilterEmail
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_FilterEmail

    private void FilterNames(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FilterNames
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_FilterNames

    private void FilterGroup(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FilterGroup
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_FilterGroup

    private void ContactCard(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ContactCard
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_ContactCard

    private void Ignore(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Ignore
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_Ignore

    private void ShowConversationLog(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowConversationLog
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_ShowConversationLog

    private void OpenIM(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenIM
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_OpenIM

    private void CallComputer(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CallComputer
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_CallComputer

    private void CallSetting(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CallSetting
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_CallSetting

    private void InviteWebcam(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InviteWebcam
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_InviteWebcam

    private void WebcamSetting(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WebcamSetting
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_WebcamSetting

    private void InviteConference(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InviteConference
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_InviteConference

    private void JoinConference(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JoinConference
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_JoinConference

    private void AllPreference(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AllPreference
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_AllPreference

    private void CallManish(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CallManish
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Yet to be Updated");
    }//GEN-LAST:event_CallManish

    private void Exit(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exit
        // TODO add your handling code here:
        //Gui6 dialog = new Gui6(this, true, myGui0);
        //dialog.setVisible(true);
        System.exit(0);
    }//GEN-LAST:event_Exit

    private void Status(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Status
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(JFrame, "Status Updated");
    }//GEN-LAST:event_Status

    private void IntiateChat(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IntiateChat
        // TODO add your handling code here:
        if (jList1.getSelectedValue()==null){
            JOptionPane.showMessageDialog(new javax.swing.JFrame(), "Please Select a buddy from the list");
        }
        else{
            Object BuddyId=jList1.getSelectedValue();
            String BuddyId1=(String) BuddyId;
            if(HashOnline.get(BuddyId).equalsIgnoreCase("O")){
                if (HashChatInstance.containsKey(BuddyId)==false){
                    new Gui2(BuddyId1,myGui0,this).setVisible(true);
                }
                else{
                    HashChatInstance.get(BuddyId).setVisible(true);
                } 
            }
            else{
                JOptionPane.showMessageDialog(new javax.swing.JFrame(), "Code for Sending message hasn't been updated");
            }          
        }
        
    }//GEN-LAST:event_IntiateChat

    private void DoubleClickListener(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DoubleClickListener
        // TODO add your handling code here:
        if(evt.getClickCount()>2){
            
        }
    }//GEN-LAST:event_DoubleClickListener

    /**
    * @param args the command line arguments
    */
    /**
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Gui1().setVisible(true);
            }
        });
    }
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    public javax.swing.JList jList1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu6;
    private javax.swing.JMenu jMenu7;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem11;
    private javax.swing.JMenuItem jMenuItem12;
    private javax.swing.JMenuItem jMenuItem13;
    private javax.swing.JMenuItem jMenuItem14;
    private javax.swing.JMenuItem jMenuItem15;
    private javax.swing.JMenuItem jMenuItem16;
    private javax.swing.JMenuItem jMenuItem17;
    private javax.swing.JMenuItem jMenuItem18;
    private javax.swing.JMenuItem jMenuItem19;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem20;
    private javax.swing.JMenuItem jMenuItem21;
    private javax.swing.JMenuItem jMenuItem22;
    private javax.swing.JMenuItem jMenuItem23;
    private javax.swing.JMenuItem jMenuItem24;
    private javax.swing.JMenuItem jMenuItem26;
    private javax.swing.JMenuItem jMenuItem27;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    private DefaultListModel lmNames = new DefaultListModel();
}
